<template>
  <div>
    <el-dialog title="设置角色" :visible="dialogFormVisible" @close="closeFn">
      <el-checkbox-group v-model="checkList">
        <el-checkbox v-for="item in rolesList" :key="item.id" :label="item.id">{{ item.title }}</el-checkbox>
      </el-checkbox-group>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="btnFn">确 定</el-button>
        <el-button @click="closeFn">取 消</el-button>
      </div>

    </el-dialog>
  </div>
</template>

<script>
import { editUserRegister } from '@/api/employees.js'
export default {
  data() {
    return {
      rolesList: [], // 角色列表
      dialogFormVisible: false, // 弹出框
      checkList: [], // 选择的角色列表
      userDetail: {} // 角色详情
    }
  },
  methods: {
    // 确定角色信息,还是使用编辑员工接口
    async btnFn() {
      await editUserRegister({ ...this.userDetail, roles: this.checkList })
      // console.log(res)

      // 关闭弹窗
      this.closeFn()
    },
    // 关闭弹窗
    closeFn() {
      this.dialogFormVisible = false

      // 清空数据
      this.checkList = [] // 选择的角色列表
      this.userDetail = {} // 角色详情
    }
  }

}
</script>

<style lang='scss' scoped>
.dialog-footer{
  text-align: center;
}
</style>
